<?php
//这里引一个开源库Mysqli封装 版本2.9.3
#https://github.com/ThingEngineer/PHP-MySQLi-Database-Class
require_once("PHPMySQLiDatabaseClass/MysqliDb.php");
require_once("db_config.php");
$db_config = new dbConfig();
$title    = $_POST['title'];
$content  = $_POST['content'];
$price    = $_POST['price'];
$poster   = $_POST['poster'];
$id       = $_POST['id'];
$type     = $_POST['type'];
$end_time = $_POST['end_time'];
//echo $end_time;
$db = new MysqliDb
(
    $db_config->host,
    $db_config->account,
    $db_config->pwd,
    'student'
);
#返回状态码
$respone_body = Array
(
    'code'  =>false,
    'msg'   =>"",
    'debug' =>"",
    'error' =>"",
);
$publish_time = date("Y-m-d");
$data = Array
(
    'id'      => $id,
    'title'   => $title,
    "content" => $content,
    "price"   => $price,
    "publish_time"=> $publish_time,
    "end_time"=> $end_time,
    "user"    => $poster,
    "allow"   => 0,
    'type'    => $type,
);
$id = $db->insert("task",$data);
if($id)
{
    $respone_body['code'] = true;
    $respone_body['msg']  = "任务提交成功，等待管理员审核";
    $respone_body['debug'] = $id;
    echo json_encode($respone_body);
}
else
{
    $respone_body['code'] = false;
    $error = $db->getLastError();
    $respone_body['msg']   = "任务提交失败,请检测标题是否与别人的任务重复";
    $respone_body['debug'] = $db->getLastError();
    echo json_encode($respone_body);
}
?>